package me.zhengjie.rest;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.domain.dto.UploadFileReqDTO;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.utils.OSSUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Api(tags = "文件模块api")
@Slf4j
@RequestMapping("/file")
public class FileController {


    @Resource
    private OSSUtils ossUtils;

    @ApiOperation("阿里云文件上传（新）")
    @PostMapping(value = "/files-anonNew")
    @SneakyThrows
    public ResponseEntity<String> fileUpload(UploadFileReqDTO uploadFileReqDTO) {
        if (uploadFileReqDTO.getFile() == null) {
            throw new BadRequestException("请上传文件");
        }
        String upload = ossUtils.upload(uploadFileReqDTO);
        return ResponseEntity.ok(upload);
    }


}
